package com.hmall.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 网关过滤器
 *
 * @Author mr.lcc
 * @Data 2025/6/20 11:19
 */
@Slf4j
//@Component
public class PrintAnyGlobalFilter implements GlobalFilter, Ordered {
    /**
     * 过滤请求
     *
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 模拟过滤请求
        log.info("打印全局过滤器，过滤路径为:{}", exchange.getRequest().getURI());
        // 放行
        return chain.filter(exchange);

        // 拦截逻辑
        //exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
        //return exchange.getResponse().setComplete();
    }

    /**
     * 优先级
     *
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }
}
